<?php
/**
 * Created by PhpStorm.
 * User: FDG296
 * Date: 2017/7/10
 * Time: 15:33
 */
namespace backend\models;

use Yii;
use yii\db\ActiveRecord;

class UserDepartment extends ActiveRecord{

    const STATUS_ENABLE = 1;
    const STATUS_DISABLE = 0;
    const DEFAULT_PARENT_ID = 0;
    const DEFAULT_SORT = 0;
    public $dept_name;
    public $creator;

    public static function tableName(){
        return '{{%user_department}}';
    }

    public function rules(){
        return [
          ['dept_name','required'],
          ['dept_name','trim'],
          ['use_flg','default','value'=>self::STATUS_DISABLE],
          ['parent_id','default','value'=>self::DEFAULT_PARENT_ID],
          ['sort','default','value'=>self::DEFAULT_SORT],
          ['creator','getCreator'],
          ['create_time','date']
        ];
    }

    /**
     * @获取创建人
     */
    public function getCreator(){
        $userInfo = \common\helps\tools::getloginUserInfo();
        if($userInfo){
            $userName = $userInfo->userName;
        }else{
            $userName = '';
        }
        return $userName;
    }
}